package com.dodock.banglapapers.server.helper;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class ExtraHeadlinesExtractor {

	
	public static ArrayList<HashMap<String, String>> getHeadlines(String url) throws IOException{
		
		ArrayList<HashMap<String, String>> headlines = new ArrayList<HashMap<String,String>>();
		
		Document doc = Jsoup.connect(url).get();
		Elements links = doc.select("a[href]");
		
		for(Element a:links){
			String href = a.attr("href");
			
			if(href.contains("details.php?newsId=")){
				String text = a.text();
				int pos = href.indexOf("=");
				String id = href.substring(pos + 1);
				
				HashMap<String, String> news = new HashMap<String, String>();
				news.put("news", text);
				news.put("id", id);
				headlines.add(news);
			}
		}
		return headlines;
	}
	
}
